package com.coco.controller;

import com.coco.dao.UserDao;
import com.coco.entity.People;
import com.coco.service.UserService;
import org.coco.core.annotation.Controller;
import org.coco.core.annotation.RequestMapping;
import org.coco.core.annotation.ResponseBody;
import org.coco.inject.annotation.Autowired;
import org.coco.mvc.annotation.RequestParam;

import java.io.File;
import java.net.URL;
import java.util.List;

@Controller
public class CocoOneController{

    @RequestMapping(value = "/getInfo")
    @ResponseBody
    public String getInfo(@RequestParam String admin, @RequestParam("num") int num) {
        System.out.println("参数admin的值 = " + admin);
        System.out.println("参数num的值 = " + num);
        return "success to getInfo";
    }

    @Autowired
    private UserService userService;

    @Autowired
    private UserDao userDao;

    @RequestMapping(value = "/test")
    @ResponseBody
    public String test() {
        System.out.println(userService.test());
        return userService.test();
    }

    @RequestMapping(value = "/proxy")
    @ResponseBody
    public String proxy() {
        List<People> admin = userDao.findAll(1, "admin");
        System.out.println("得到的结果是：" + admin.size());
        System.out.println("用户名称是：" + admin.get(0).getName());
        return "proxy success";
    }

    @RequestMapping(value = "/findById")
    @ResponseBody
    public Object findById() {
        List<People> peoples = userDao.findByName("admin");
        return peoples;
    }

    @RequestMapping("/delById")
    @ResponseBody
    public Integer delById(@RequestParam("id") Integer id) {
        int i = userDao.delById(id);
        return i;
    }


    @RequestMapping("/add")
    @ResponseBody
    public String add() {
        People people = new People();
        people.setName("flink");
        userDao.add(people);
        return "success";
    }
}
